package com.leyou.sh.search.web;

import com.leyou.sh.search.dto.SearchParamDTO;
import com.leyou.sh.search.entity.Goods;
import com.leyou.sh.search.service.SearchService;
import com.leyou.starter.elastic.entity.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;

/**
 * @author balisong_fcs
 * @date 2021/1/5 18:16
 * @desc
 */
@RequestMapping("/goods")
@RestController
public class SearchController {

    @Autowired
    private SearchService searchService;

    @GetMapping("/suggestion")
    public Mono<List<String>> getSuggest(
            @RequestParam("key") String key) {
        return this.searchService.getSuggest(key);
    }

    @PostMapping("/list")
    public Mono<PageInfo<Goods>> searchGoods(@RequestBody SearchParamDTO request) {
        return searchService.searchGoods(request);
    }

    @PostMapping("/filter")
    public Mono<Map<String,List<? extends Object>>> listFilter(@RequestBody SearchParamDTO request) {
        return searchService.listFilter(request);
    }
}
